<?php


namespace app\admin\controller;


use app\BaseController;
use app\common\model\mysql\PersonModel;
use think\facade\Db;

class Data extends BaseController
{

    public function test1(){
        $result = app('db')->table('person')->where('id', 1)->find();
        dump($result);
    }

    public function test2(){
        $result = Db::table('person')
                //->order('id', 'desc')
                //->limit(1, 1)
                //->page(1, 1)
                ->where([
                    ['id', '=', 3],
                    ['id', 'in', '1, 2']
                ])
                ->select();
        dump($result);
    }

    /**
     * 输出sql
     */
    public function test3(){
        //方式1 "SELECT * FROM `db_person`"
        $result = Db::table('person')->fetchSql()->select();
        dump($result);

        //方式2 "SHOW FULL COLUMNS FROM `db_person`"
        Db::table('db_person')->fetchSql()->select();
        dump(Db::getLastSql()); exit();
    }

    /**
     * 使用model
     */
    public function test4(){
        $result = PersonModel::find(1);
        dump($result->toArray());
    }

    public function test5(){
        $personModel = new PersonModel();
        $result = $personModel->where('id', 1)->select();
        dump($result->toArray());
    }



}